package com.polaris.live.popup.party

import android.content.Context
import android.graphics.Color
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.cacha.CacheUtil
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.util.DateUtils
import com.polaris.live.databinding.PopupClosePartyBinding
import com.polaris.live.translation.R.string

/**
 *  关闭语聊房
 * @author Created by 天晴 on 2024/2/27 19:18
 * @since 1.0.0
 **/
class ClosePartyPopup(
    context: Context,
    private val startLiveTime: Long,
    private val onCloseLiveCallBack: () -> Unit
) : CenterPopupView(context) {
    private lateinit var mBinding: PopupClosePartyBinding
    override fun getImplLayoutId(): Int {
        return R.layout.popup_close_party
    }


    override fun onCreate() {
        super.onCreate()
        mBinding = PopupClosePartyBinding.bind(popupImplView)
        val time = CacheUtil.getServerTime() - startLiveTime
        val span = SpanUtils.with(mBinding.liveTime)
            .append(StringUtils.getString(string.living_time))
            .setForegroundColor(Color.parseColor("#202028"))
            .append(" ${DateUtils.formatDuration(time)}")
            .setForegroundColor(Color.parseColor("#FE1849"))
            .create()

        mBinding.liveTime.text = span
        mBinding.cancel.setOnSingleClickListener {
            dismiss()
        }
        mBinding.closeLive.setOnSingleClickListener {
            dismiss()
            onCloseLiveCallBack.invoke()
        }
    }
}